﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace Bus_proj.website
{
    public partial class ticket_user_chk : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection("Data Source=MONSTERTUA;Initial Catalog=Bus_pro;User ID=sa1;Password=qwerty123");
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    //string ddsd = Session["login_Access_id"].ToString();
                    if (Int32.Parse(Session["login_Access_id"].ToString()) == 1)
                    {
                        string drive = @"select DISTINCT payment_id,Around_date,Route_source,Route_destination
                            from Table_payment 
                            inner join Table_Sale 
                            on Table_payment.Sale_id = Table_Sale.Sale_id 
                            inner join Table_Around 
                            on Table_Sale.Around_id = Table_Around.Around_id 
                            inner join Table_Route 
                            on Table_Around.Route_id = Table_Route.Route_id
                            where Passenger_id = '" + Session["login_User"] + "' and Around_date>= GETDATE()";
                        string drive2 = @"select Table_Sale.Sale_id,Table_Around.Around_date,Table_Route.Route_source,Table_Route.Route_destination,Table_SaleDetail.Seat_no,Table_SSID.SS_name
                            from Table_Sale
                            inner join Table_Around
                            on Table_Sale.Around_id = Table_Around.Around_id
                            inner join Table_Route
                            on Table_Around.Route_id = Table_Route.Route_id
                            inner join Table_SaleDetail
                            on Table_Sale.Sale_id = Table_SaleDetail.Sale_id
                            inner join Table_SSID
                            on Table_Sale.SSID = Table_SSID.SSID
                            where Passenger_id = '" + Session["login_User"] + "' and Around_date>= GETDATE() and (Table_SSID.SSID=1 or Table_SSID.SSID=3 or Table_SSID.SSID=4 or Table_SSID.SSID=5)";
                        SqlCommand sqlcomm = new SqlCommand();
                        string Connection = ConfigurationManager.ConnectionStrings["Bus_proConnectionString"].ConnectionString;
                        SqlConnection sqlconn = new SqlConnection(Connection);
                        SqlDataAdapter da = new SqlDataAdapter(drive, sqlconn);
                        SqlDataAdapter da2 = new SqlDataAdapter(drive2, sqlconn);
                        DataTable dt = new DataTable();
                        da.Fill(dt);
                        DataTable dt2 = new DataTable();
                        da2.Fill(dt2);
                        GridView1.DataSource = dt2;
                        GridView1.DataBind();
                        GridView2.DataSource = dt;
                        GridView2.DataBind();
                    }
                    else
                    {
                        Response.Redirect("login.aspx");
                    }
                }
                catch (Exception)
                {
                    Response.Redirect("login.aspx");
                }

            }
            
        }       
    }
}